package org.learn.intermediate;
//为了封装，写三个private
public class Account {
    private String name;
    private double balance;
    private String pwd;


    //提供两个构造器,无参构造器和有属性的构造器

    public Account(){
    }

    public Account(String name, double balance, String pwd) {
        this.setName(name);
        this.setBalance(balance);
        this.setPwd(pwd);
    }

    public String getName() {
        return name;
    }
//姓名（长度234个字符）
    public void setName(String name) {
        if(name.length() >= 2 && name.length() <= 4) {
            this.name = name;
        }else{
            System.out.println("姓名要求长度为2-4");
            this.name = "无名";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if(balance > 20) {
            this.balance = balance;
        }else {
            System.out.println("余额必须大于20，默认为0");
        }
    }

    public String getPwd() {
        return pwd;
    }

    public void setPwd(String pwd) {
        if(pwd.length() == 6) {
            this.pwd = pwd;
        }else{
            System.out.println("密码必须是六位，默认密码是 000000");
            this.pwd ="000000";
        }
    }
    public void showInfo(){
        System.out.println("账户信息 name = " + name + "余额=" + balance + "密码");
    }
}

